const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CleanWebpackPlugin = require("clean-webpack-plugin");

module.exports = {
    mode:'development',
    entry: {
        popup:'./popup.js',
        numImage:'./numImage.js',
        backwork:'./backwork.js'
    },
    plugins:[
        new CleanWebpackPlugin.CleanWebpackPlugin(),
        new CopyWebpackPlugin([
            {
                from: path.resolve(__dirname, 'manifest.json'),
                to: path.resolve(__dirname, 'dist/manifest.json'),
                ignore: ['.*']
            },
            {
                from: path.resolve(__dirname, 'popup.html'),
                to: path.resolve(__dirname, 'dist/popup.html'),
                ignore: ['.*']
            },
            {
                from: path.resolve(__dirname, './assets'),
                to: path.resolve(__dirname, 'dist/assets'),
                ignore: ['.*']
            },
        ]),
    ],
    // resolve:{
    //     modules:['./node_modules/_puppeteer@1.20.0@puppeteer/node6','node_modules']
    // },
    module:{
        rules: [
            {
              test: /\.js$/, // 处理以.js结尾的文件
              loader: 'babel-loader', // 用babel-loader处理
              options: {
                presets: [
                  [
                    '@babel/preset-env', // 使用babel预设，转换ES6+到ES5
                    {
                      targets: '> 0.25%, not dead', // 根据浏览器市场份额和死亡浏览器来转换
                    },
                  ],
                ],
              },
            }
        ]
    },
    target:'web',
    //devtool:'eval-source-map',
    devtool:'nosources-source-map',
    output: {
        path: path.resolve(__dirname, 'dist'),
    },
    // node: {
    //     dns: "mock",
    //     fs: "empty",
    //     path: true,
    //     url: false
    // }
  };